<?php

namespace App\Services;

use App\Models\AdminModel;
use App\Models\StorageModel;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Str;

class MessageService
{

    /**
     * 出库提醒
     * 仓库负责人和操作人可接收该消息提醒
     * @param $materielName 商品名称
     * @param $typeName 商品类型名称
     * @param $inStorageNum 当前在库数量
     * @param $storageName 仓库名
     * @param $num 操作数量
     * @param $userId 子账号id
     * @param $storageId 仓库id
     * @param $alertNum 低库存预警数
     * @return bool
     */
    public static function sendOutSms($materielName, $typeName, $inStorageNum, $storageName, $num, $data, $storageId, $alertNum, $logId = 0)
    {
        $adminInfo = AdminModel::where('id', $data['main_id'])->first();
        $userInfo = [];
        if ($data['main_id'] !== $data['user_id']) {
            $userInfo = AdminModel::where('id', $data['user_id'])->first();
        }
        $aInfo = !empty($userInfo) ? $userInfo : $adminInfo;
        /* if($inStorageNum > $alertNum) { */
        $storageManagerInfo = StorageModel::select(
            'mobile',
            'gz_openid',
            'device_id'
        )
            ->from('storage as a')
            ->leftJoin('admin as b', 'b.id', '=', 'a.user_id')
            ->where('a.id', $storageId)
            ->first();

        if ($adminInfo['device_id'] == $storageManagerInfo['device_id']) {

            if (!empty($adminInfo['device_id'])) {
                //个推-出库操作人
                GeTuiService::push(
                    '出库提醒',
                    '仓库：' . $storageName .
                    '中商品：' . $materielName . '-' .
                    $typeName . '已成功出库，出库数量:' . $num,
                    $adminInfo['device_id'],
                );
            }

            if (!empty($userInfo['device_id'])) {
                //个推-出库操作人
                GeTuiService::push(
                    '出库提醒',
                    '仓库：' . $storageName .
                    '中商品：' . $materielName . '-' .
                    $typeName . '已成功出库，出库数量:' . $num,
                    $userInfo['device_id'],
                );
            }
        } else {

            if (!empty($adminInfo['device_id'])) {
                //个推-出库操作人
                GeTuiService::push(
                    '出库提醒',
                    '仓库：' . $storageName .
                    '中商品：' . $materielName . '-' .
                    $typeName . '已成功出库，出库数量:' . $num,
                    $adminInfo['device_id'],
                );
            }
            if (!empty($userInfo) && $userInfo['device_id'] == $storageManagerInfo['device_id']) {

                if (!empty($userInfo['device_id'])) {
                    //个推-仓库负责人
                    GeTuiService::push(
                        '出库提醒',
                        '仓库：' . $storageName .
                        '中商品：' . $materielName . '-' .
                        $typeName . '已成功出库，出库数量:' . $num,
                        $userInfo['device_id'],
                    );
                }
            } else {

                if (!empty($storageManagerInfo['device_id'])) {
                    //个推-仓库负责人
                    GeTuiService::push(
                        '出库提醒',
                        '仓库：' . $storageName .
                        '中商品：' . $materielName . '-' .
                        $typeName . '已成功出库，出库数量:' . $num,
                        $storageManagerInfo['device_id'],
                    );

                }

                if (!empty($userInfo['device_id'])) {
                    //个推-仓库负责人
                    GeTuiService::push(
                        '出库提醒',
                        '仓库：' . $storageName .
                        '中商品：' . $materielName . '-' .
                        $typeName . '已成功出库，出库数量:' . $num,
                        $userInfo['device_id'],
                    );
                }
            }
        }
        $time = !empty($data['out_storage_time']) ?
            date('Y年m月d日 H:i', $data['out_storage_time']) :
            date('Y年m月d日 H:i', time());
        $msgContent = [
            'appid' => config('app.wechat_app_id'),
            'template_id' => 'Qd2W-aiBFvPeAzjoJEHjPhiCHr6XAkHwbWo82eFGo74',
            'url' => '',
            'miniprogram' => [
                'appid' => config('app.miniapp_id'),
                "pagepath" => "storePackage/records/detail?id=" . $logId . "&type=1"
            ],
            'data' => [
                'thing2' => ['value' => self::subStrLenth($storageName)],
                'thing3' => ['value' => self::subStrLenth($materielName)],
                'character_string14' => ['value' => $num],
                'time6' => ['value' => $time],
                'thing15' => ['value' => $aInfo['nickname'] ?? $aInfo['username']],
            ]
        ];
        return self::opendIdMess($adminInfo, $userInfo ?? [], $msgContent, $storageManagerInfo);
    }

    private static function subStrLenth(string $str): string
    {
        if (Str::length($str) > 20) {
            $str = mb_substr($str, 0, 20, 'UTF-8');
            $str = mb_substr($str, 0, -3) . '...';
        }
        return $str;
    }

    /**
     * 库存不足提醒
     * 主账号以及仓库负责人可接收该消息提醒
     * @param $materielName 商品名称
     * @param $typeName 商品类型名称
     * @param $inStorageNum 当前在库数量
     * @param $mainId 主账号id
     * @param $storageName 仓库名
     * @param $storageId 仓库id
     * @return bool
     */
    public static function sendShortSms($materielName, $typeName, $inStorageNum, $data, $storageName, $storageId)
    {
        //$mainInfo = AdminModel::where('id', $mainId)->first();
        $userInfo = [];
        if ($data['main_id'] == $data['user_id']) {
            $mainInfo = AdminModel::where('id', $data['main_id'])->first();
        } else {
            $mainInfo = AdminModel::where('id', $data['main_id'])->first();
            $userInfo = AdminModel::where('id', $data['user_id'])->first();
        }

        $storageManagerInfo = StorageModel::select(
            'mobile',
            'gz_openid',
            'device_id'
        )
            ->from('storage as a')
            ->leftJoin('admin as b', 'b.id', '=', 'a.user_id')
            ->where('a.id', $storageId)
            ->first();

        if ($inStorageNum == 0) {
//            $info = [
//                'storage' => $storageName,
//                'materiel' => $materielName.'-'.$typeName,
//                'num' => $inStorageNum
//            ];

//            if(!empty($storageManagerInfo['mobile'])) {
//                if($mainInfo['mobile'] == $storageManagerInfo['mobile']) {
//                    //短信-推送至主账号
//                    SmsService::sendStorageAlertMsg(
//                        $info,
//                        $mainInfo['mobile'],
//                        config('app.short_template_id')
//                    );
//                }
//                else {
//                    //短信-推送至主账号
//                    SmsService::sendStorageAlertMsg(
//                        $info,
//                        $mainInfo['mobile'],
//                        config('app.short_template_id')
//                    );
//
//                    //短信-推送至仓库负责人
//                    SmsService::sendStorageAlertMsg(
//                        $info,
//                        $storageManagerInfo['mobile'],
//                        config('app.short_template_id')
//                    );
//                }
//            }
//            else {
//                //短信-推送至主账号
//                SmsService::sendStorageAlertMsg(
//                    $info,
//                    $mainInfo['mobile'],
//                    config('app.short_template_id')
//                );
//            }


            if ($mainInfo['device_id'] == $storageManagerInfo['device_id']) {
                if (!empty($mainInfo['device_id'])) {
                    //个推-主账号
                    GeTuiService::push(
                        '库存不足',
                        '仓库：' . $storageName .
                        '中商品：' . $materielName . '-' .
                        $typeName . '剩余库存数不足，当前剩余库存数：' .
                        $inStorageNum . '为避免影响使用，请及时补充库存',
                        $mainInfo['device_id'],
                    );
                }

                if (!empty($userInfo['device_id'])) {
                    //个推-操作
                    GeTuiService::push(
                        '库存不足',
                        '仓库：' . $storageName .
                        '中商品：' . $materielName . '-' .
                        $typeName . '剩余库存数不足，当前剩余库存数：' .
                        $inStorageNum . '为避免影响使用，请及时补充库存',
                        $userInfo['device_id'],
                    );
                }
            } else {
                if (!empty($mainInfo['device_id'])) {
                    //个推-主账号
                    GeTuiService::push(
                        '库存不足',
                        '仓库：' . $storageName .
                        '中商品：' . $materielName . '-' .
                        $typeName . '剩余库存数不足，当前剩余库存数：' .
                        $inStorageNum . '为避免影响使用，请及时补充库存',
                        $mainInfo['device_id'],
                    );
                }

                if (!empty($userInfo) && $userInfo['device_id'] == $storageManagerInfo['device_id']) {

                    if (!empty($userInfo['device_id'])) {
                        //个推-操作
                        GeTuiService::push(
                            '库存不足',
                            '仓库：' . $storageName .
                            '中商品：' . $materielName . '-' .
                            $typeName . '剩余库存数不足，当前剩余库存数：' .
                            $inStorageNum . '为避免影响使用，请及时补充库存',
                            $userInfo['device_id'],
                        );
                    }
                } else {

                    if (!empty($storageManagerInfo['device_id'])) {
                        //个推-仓库负责人
                        GeTuiService::push(
                            '库存不足',
                            '仓库：' . $storageName .
                            '中商品：' . $materielName . '-' .
                            $typeName . '剩余库存数不足，当前剩余库存数：' .
                            $inStorageNum . '为避免影响使用，请及时补充库存',
                            $storageManagerInfo['device_id'],
                        );
                    }

                    if (!empty($userInfo['device_id'])) {
                        //个推-操作
                        GeTuiService::push(
                            '库存不足',
                            '仓库：' . $storageName .
                            '中商品：' . $materielName . '-' .
                            $typeName . '剩余库存数不足，当前剩余库存数：' .
                            $inStorageNum . '为避免影响使用，请及时补充库存',
                            $userInfo['device_id'],
                        );
                    }
                }
            }

            $msgContent = [
                'appid' => config('app.wechat_app_id'),
                'template_id' => 'ByVc8g70hg6rEfZaQ_NVyHtgmWoWR79nRaqGcs9cjjA',
                'url' => '',
                'miniprogram' => '',
                'data' => [//值得消息模板
                    'thing2' => ['value' => self::subStrLenth($storageName)],
                    'thing3' => ['value' => self::subStrLenth($materielName)],
                    'character_string4' => ['value' => $inStorageNum],
                    'time5' => ['value' => date('Y年m月d日')],
                ]
            ];
            return self::opendIdMess($mainInfo, $userInfo ?? [], $msgContent, $storageManagerInfo);
        }

        return true;
    }

    /**
     * 入库提醒
     * 仅仓库负责人和操作人可接收该消息
     * @param $materielName
     * @param $typeName
     * @param $storageId
     * @param $storageName
     * @param $userId
     * @param $num //操作数量
     * @param $inStorageNum
     * @return bool
     */
    public static function sendInSms($purchaseNo, $materielName, $typeName, $storageId, $storageName, $data, $num, $inStorageNum, $inLogId = 0)
    {
        //$adminInfo = AdminModel::where('id', $userId)->first();
        $userInfo = [];
        if ($data['main_id'] == $data['user_id']) {
            $adminInfo = AdminModel::where('id', $data['main_id'])->first();

        } else {
            $adminInfo = AdminModel::where('id', $data['main_id'])->first();
            $userInfo = AdminModel::where('id', $data['user_id'])->first();
        }

        $storageManagerInfo = StorageModel::select(
            'mobile',
            'gz_openid',
            'device_id'
        )
            ->from('storage as a')
            ->leftJoin('admin as b', 'b.id', '=', 'a.user_id')
            ->where('a.id', $storageId)
            ->first()->toArray();

        if ($adminInfo['device_id'] == $storageManagerInfo['device_id']) {
            if (!empty($adminInfo['device_id'])) {
                //个推-主账号
                GeTuiService::push(
                    '入库提醒',
                    '商品：' . $materielName . '-' .
                    $typeName . '已成功入库至仓库:' . $storageName . '，当前剩余库存数：' .
                    $inStorageNum . '入库操作数量:' . $num,
                    $adminInfo['device_id'],
                );
            }

            if (!empty($userInfo['device_id'])) {
                //个推-操作人
                GeTuiService::push(
                    '入库提醒',
                    '商品：' . $materielName . '-' .
                    $typeName . '已成功入库至仓库:' . $storageName . '，当前剩余库存数：' .
                    $inStorageNum . '入库操作数量:' . $num,
                    $userInfo['device_id'],
                );
            }
        } else {
            if (!empty($adminInfo['device_id'])) {
                //个推-主账号
                GeTuiService::push(
                    '入库提醒',
                    '商品：' . $materielName . '-' .
                    $typeName . '已成功入库至仓库:' . $storageName . '，当前剩余库存数：' .
                    $inStorageNum . '入库操作数量:' . $num,
                    $adminInfo['device_id'],
                );
            }


            if (!empty($userInfo) && $userInfo['device_id'] == $storageManagerInfo['device_id']) {
                if (!empty($userInfo['device_id'])) {
                    //个推-操作人
                    GeTuiService::push(
                        '入库提醒',
                        '商品：' . $materielName . '-' .
                        $typeName . '已成功入库至仓库:' . $storageName . '，当前剩余库存数：' .
                        $inStorageNum . '入库操作数量:' . $num,
                        $userInfo['device_id'],
                    );
                }
            } else {
                if (!empty($storageManagerInfo['device_id'])) {
                    //个推-主账号
                    GeTuiService::push(
                        '入库提醒',
                        '商品：' . $materielName . '-' .
                        $typeName . '已成功入库至仓库:' . $storageName . '，当前剩余库存数：' .
                        $inStorageNum . '入库操作数量:' . $num,
                        $storageManagerInfo['device_id'],
                    );
                }

                if (!empty($userInfo['device_id'])) {
                    //个推-操作人
                    GeTuiService::push(
                        '入库提醒',
                        '商品：' . $materielName . '-' .
                        $typeName . '已成功入库至仓库:' . $storageName . '，当前剩余库存数：' .
                        $inStorageNum . '入库操作数量:' . $num,
                        $userInfo['device_id'],
                    );
                }
            }
        }

        $msgContent = [
            'appid' => config('app.wechat_app_id'),
            'template_id' => config('app.in_tmpl'),
            'url' => '',
            'miniprogram' => [
                'appid' => config('app.miniapp_id'),
                "pagepath" => "storePackage/records/detail?id=" . $inLogId . "&type=0"
            ],
            'data' => [//值得消息模板
                'thing2' => ['value' => self::subStrLenth($storageName)],
                'thing3' => ['value' => self::subStrLenth($materielName)],
                'number9' => ['value' => $num],
                'time6' => ['value' => date('Y年m月d日 H:i')],
            ]
        ];
        return self::opendIdMess($adminInfo, $userInfo ?? [], $msgContent, $storageManagerInfo);
    }

    /**
     * 低库存预警消息提醒
     * 主账号接收预警提醒；仓库负责人接收出库提醒
     * @param $materielName 商品名称
     * @param $typeName 商品类型名称
     * @param $inStorageNum 当前在库数量
     * @param $alertNum 低库存预警数
     * @param $mainId 主账号id
     * @param $storageName 仓库名
     * @return bool
     */
    public static function sendAlertSms($materielName, $typeName, $inStorageNum, $alertNum, $data, $storageId, $storageName, $num)
    {
        $userInfo = [];
        if ($data['main_id'] == $data['user_id']) {
            $mainInfo = AdminModel::where('id', $data['main_id'])->first();

        } else {
            $mainInfo = AdminModel::where('id', $data['main_id'])->first();
            $userInfo = AdminModel::where('id', $data['user_id'])->first();
        }

        $storageManagerInfo = StorageModel::select(
            'mobile',
            'gz_openid',
            'device_id'
        )
            ->from('storage as a')
            ->leftJoin('admin as b', 'b.id', '=', 'a.user_id')
            ->where('a.id', $storageId)
            ->first();

        $info = [
            'storage' => $storageName,
            'materiel' => $materielName . '-' . $typeName,
            'num' => $inStorageNum
        ];

        //库存数达到预警
        if ($inStorageNum != 0 && $inStorageNum <= $alertNum) {
//            SmsService::sendStorageAlertMsg(
//                $info,
//                $mainInfo['mobile'],
//                config('app.alert_template_id')
//            );

            //个推-主账号
            GeTuiService::push(
                '库存预警',
                '仓库：' . $storageName .
                '中商品：' . $materielName . '-' .
                $typeName . '剩余库存数达到警戒值，当前剩余库存数：' .
                $inStorageNum . '为避免影响正常使用，请及时补充库存',
                $mainInfo['device_id'],
            );
            if (!empty($userInfo)) {
                //个推-操作人
                GeTuiService::push(
                    '库存预警',
                    '仓库：' . $storageName .
                    '中商品：' . $materielName . '-' .
                    $typeName . '剩余库存数达到警戒值，当前剩余库存数：' .
                    $inStorageNum . '为避免影响正常使用，请及时补充库存',
                    $userInfo['device_id'],
                );
            }
            $msgContent = [
                'appid' => config('app.wechat_app_id'),
                'template_id' => 'ByVc8g70hg6rEfZaQ_NVyHtgmWoWR79nRaqGcs9cjjA',
                'url' => '',
                'miniprogram' => '',
                'data' => [//值得消息模板
                    'thing2' => ['value' => self::subStrLenth($storageName)],
                    'thing3' => ['value' => self::subStrLenth($materielName)],
                    'character_string4' => ['value' => $inStorageNum],
                    'time5' => ['value' => date('Y年m月d日')],
                ]
            ];
            return self::opendIdMess($mainInfo, $userInfo ?? [], $msgContent, $storageManagerInfo);
        }
        return true;
    }

    /**
     * 批次号到期预警消息提醒
     * 主账号接收预警提醒；仓库负责人接收出库提醒
     * @param $materielName 商品名称
     * @param $typeName 商品类型名称
     * @param $inStorageNum 当前在库数量
     * @param $alertNum 低库存预警数
     * @param $mainId 主账号id
     * @param $storageName 仓库名
     * @return bool
     */
    public static function sendStorageBatchAlertSms($data)
    {
        $msgContent = [];
        switch ($data['type']) {
            case 1:
                $msgContent = [
                    'appid' => config('app.wechat_app_id'),
                    'template_id' => 'jdco2PfM7WOCDqtOscjIK1PQNDsojK4cN2pNe5HKBj8',
                    'url' => '',
                    'miniprogram' => '',
                    'data' => [
                        'thing15' => ['value' => $data['storage_name'] . '-批次号到期'],
                        'thing10' => ['value' => $data['materiel_name']],
                        'character_string11' => ['value' => $data['batch_no']],
                        'number7' => ['value' => $data['batch_left_num']],
                        'time18' => ['value' => $data['date']],
                    ]
                ];
                break;
            case 2:
                $msgContent = [
                    'appid' => config('app.wechat_app_id'),
                    'template_id' => config('app.alert_tmpl'),
                    'url' => '',
                    'miniprogram' => '',
                    'data' => [
                        'first' => ['value' => '商品批次号数量不足'],
                        'keyword1' => ['value' => self::subStrLenth($data['materiel_name'])],
                        'keyword2' => ['value' => '批次号：' . $data['batch_no']],
                        'keyword3' => ['value' => 0],
                        'remark' => ['value' => '仓库的商品仓库批次号剩余数量已用完，请及时处理']
                    ]
                ];
                break;
        }

        if (!empty($data['type'])) {
            //给主账号推送公众号信息
            if (!empty($data['main_openid'])) {
                SELF::pushMsg(
                    $data['main_openid'],
                    $msgContent
                );
            }
            if ($data['main_openid'] != $data['storage_openid']) {
                //给仓库负责人推送公众号信息
                if (!empty($data['storage_openid'])) {
                    SELF::pushMsg(
                        $data['storage_openid'],
                        $msgContent
                    );
                }
            }
        }
    }

    /**
     * 销售欠款提醒推送
     */
    public static function debtReminderMessage($data)
    {
        $msgContent = [
            'appid' => config('app.wechat_app_id'),
            'template_id' => 'vC_XyLGQvfQsEu5EP2K2msAdhL3PesEoIqAY03WVrSo',
            'url' => '',
            'miniprogram' => '',
            'data' => [
                'character_string1' => ['value' => $data['order_no']],
                'thing5' => ['value' => $data['name']],
                'amount8' => ['value' => $data['debt']],
                'const11' => ['value' => $data['remark']],
                'time6' => ['value' => $data['time']],
            ]
        ];

        //给仓库负责人推送公众号信息
        if (!empty($data['gz_openid'])) {
            SELF::pushMsg(
                $data['gz_openid'],
                $msgContent
            );
        }
    }

    /**
     * 购买vip存储空间到期消息推送
     */
    public static function buyerVipSpaceMessage($data)
    {
        $msgContent = [
            'appid' => config('app.wechat_app_id'),
            'template_id' => 'vxNUN8uMsH-5o1eMdcvz72GK21LaIzWHogsYaqcfrB0',
            'url' => '',
            'miniprogram' => '',
            'data' => [
                'time15' => ['value' => $data['time']],
                'phone_number12' => ['value' => $data['phone']],
                'thing4' => ['value' => $data['type']],
                'thing6' => ['value' => $data['mark']],
            ]
        ];

        //给仓库负责人推送公众号信息
        if (!empty($data['gz_openid'])) {
            SELF::pushMsg(
                $data['gz_openid'],
                $msgContent
            );
        }
    }

    private static function pushMsg($openId, $msgContent)
    {
        $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . SELF::getAccessToken();
        $data = array_merge(['touser' => $openId], $msgContent);

        $result = SELF::httpPostData($url, $data);

        //Log::debug('出库:'.var_export($result, true));
        return true;
    }

    /**发起网络请求  获取 access_token */
    private static function getAccessToken()
    {
        if (!Redis::exists('gz_wechat_token')) {
            $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . config('app.wechat_app_id') . "&secret=" . config('app.wechat_app_secret');
            $info = file_get_contents($url);
            $json = json_decode($info);
            $arr = get_object_vars($json);
            Redis::setex('gz_wechat_token', 7200, $arr['access_token']);
        }
        return Redis::get('gz_wechat_token');
    }

    /**http - post请求*/
    private static function httpPostData($url, $data)
    {
        $data = json_encode($data);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json; charset=utf-8',
            'Content-Length: ' . strlen($data)
        ));
        $returnContent = curl_exec($ch);

        return $returnContent;
    }

    /**发起网络请求  获取 access_token */
    public static function getCsAccessToken()
    {
        if (!Redis::exists('wechat_token')) {
            //$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".config('app.miniapp_id')."&secret=".config('app.miniapp_secret');
            $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . config('app.wechat_app_id') . "&secret=" . config('app.wechat_app_secret');
            echo $url;
            $info = file_get_contents($url);
            $json = json_decode($info);
            $arr = get_object_vars($json);

            Redis::setex('wechat_token', 7200, $arr['access_token']);
        }

        return Redis::get('wechat_token');
    }

    /**
     *
     * Author: zlf
     * Created at 2024/8/14 9:59
     * @param $adminInfo
     * @param array $userInfo
     * @param array $msgContent
     * @param $storageManagerInfo
     * @return true
     */
    public static function opendIdMess($adminInfo, $userInfo = [], array $msgContent, $storageManagerInfo): bool
    {
        if (empty($userInfo)) $userInfo['gz_openid'] = [];
        if ($adminInfo['id'] === 52) {
            $openId = AdminModel::query()
                ->where('id', 19158)
                ->value('gz_openid');
            if (!empty($openId)) {
                //操作人接收消息
                SELF::pushMsg(
                    $openId,
                    $msgContent,
                );
            }
        }
        if ($adminInfo['gz_openid'] == $storageManagerInfo['gz_openid']) {
            if (!empty($adminInfo['gz_openid'])) {
                //操作人接收消息
                SELF::pushMsg(
                    $adminInfo['gz_openid'],
                    $msgContent,
                );
            }

            if (!empty($userInfo['gz_openid'])) {
                //操作人接收消息
                SELF::pushMsg(
                    $userInfo['gz_openid'],
                    $msgContent,
                );
            }
        } else {
            if (!empty($adminInfo['gz_openid'])) {
                //操作人接收消息
                SELF::pushMsg(
                    $adminInfo['gz_openid'],
                    $msgContent,
                );
            }
            if (!empty($userInfo) && $userInfo['gz_openid'] == $storageManagerInfo['gz_openid']) {
                if (!empty($userInfo['gz_openid'])) {
                    //仓库负责人接收消息
                    SELF::pushMsg(
                        $userInfo['gz_openid'],
                        $msgContent,
                    );
                }
            } else {
                if (!empty($storageManagerInfo['gz_openid'])) {
                    //仓库负责人接收消息
                    SELF::pushMsg(
                        $storageManagerInfo['gz_openid'],
                        $msgContent,
                    );
                }
                if (!empty($userInfo['gz_openid'])) {
                    //仓库负责人接收消息
                    SELF::pushMsg(
                        $userInfo['gz_openid'],
                        $msgContent,
                    );
                }
            }
        }

        return true;
    }
}
